#include<bits/stdc++.h>
using namespace std;
using ll = long long;
ll n, c;
ll a[1000001];
ll f[100001][101];
ll ask(ll x,ll y) {
	if(x>=y)
		return x-y;
	return c;
}
int main() {
	freopen("minimize.in", "r", stdin);
	freopen("minimize.out", "w", stdout);
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	cin >> n >> c;
	if (c == 0) {
		cout << 0;
		return 0;
	} else {
		for (int i = 1; i <= n; i++)
			cin >> a[i];
		for (int i = 1; i <= n; i++)
			for (int j = 0; j <= 100; j++)
				f[i][j] = LONG_LONG_MAX;
		for (int i = 1; i <= n; i++) {
			for (int j = 0; j <= 100; j++)
				f[i][j] = min(f[i][j],f[i-1][j]+ask(j,a[i]));
			for (int j = 99; j >= 0; j--)
				f[i][j] = min(f[i][j + 1], f[i][j]);
		}
		cout<<f[n][0];
	}
	return 0;
}
